package cn.hznc.constant;

import cn.hznc.domain.entity.OrderEntity;
import cn.hznc.vo.SubProgramUsageReportVo;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author：Administrator
 * @Date：2023/11/23 15:45
 */
public enum SortSubprogramEnum implements SortSubProgram{

    MinTime{
        @Override
        public List<SubProgramUsageReportVo> sortByCondition(List<SubProgramUsageReportVo> subProgramUsageReportVos, Integer sortType) {
            if(sortType == 0){
                //正序
                return subProgramUsageReportVos
                        .stream()
                        .sorted(Comparator.comparing(SubProgramUsageReportVo::getMinTime , Comparator.nullsLast(Long::compareTo)))
                        .collect(Collectors.toList());
            }
            //倒序
            return subProgramUsageReportVos
                    .stream()
                    .sorted(Comparator.comparing(SubProgramUsageReportVo::getMinTime , Comparator.nullsFirst(Long::compareTo).reversed()))
                    .collect(Collectors.toList());
        }
    },

    MaxTime{
        @Override
        public List<SubProgramUsageReportVo> sortByCondition(List<SubProgramUsageReportVo> subProgramUsageReportVos, Integer sortType) {
            if(sortType == 0){
                //正序
                return subProgramUsageReportVos
                        .stream()
                        .sorted(Comparator.comparing(SubProgramUsageReportVo::getMaxTime , Comparator.nullsLast(Long::compareTo)))
                        .collect(Collectors.toList());
            }
            //倒序
            return subProgramUsageReportVos
                    .stream()
                    .sorted(Comparator.comparing(SubProgramUsageReportVo::getMaxTime , Comparator.nullsFirst(Long::compareTo).reversed()))
                    .collect(Collectors.toList());
        }
    },

    AvgTime{
        @Override
        public List<SubProgramUsageReportVo> sortByCondition(List<SubProgramUsageReportVo> subProgramUsageReportVos, Integer sortType) {
            if(sortType == 0){
                //正序
                return subProgramUsageReportVos
                        .stream()
                        .sorted(Comparator.comparing(SubProgramUsageReportVo::getAvgTime , Comparator.nullsLast(Long::compareTo)))
                        .collect(Collectors.toList());
            }
            //倒序
            return subProgramUsageReportVos
                    .stream()
                    .sorted(Comparator.comparing(SubProgramUsageReportVo::getAvgTime , Comparator.nullsFirst(Long::compareTo).reversed()))
                    .collect(Collectors.toList());
        }
    },

    Time{
        @Override
        public List<SubProgramUsageReportVo> sortByCondition(List<SubProgramUsageReportVo> subProgramUsageReportVos, Integer sortType) {
            if(sortType == 0){
                //正序
                return subProgramUsageReportVos
                        .stream()
                        .sorted(Comparator.comparing(SubProgramUsageReportVo::getTime , Comparator.nullsLast(Long::compareTo)))
                        .collect(Collectors.toList());
            }
            //倒序
            return subProgramUsageReportVos
                    .stream()
                    .sorted(Comparator.comparing(SubProgramUsageReportVo::getTime , Comparator.nullsFirst(Long::compareTo).reversed()))
                    .collect(Collectors.toList());
        }
    };

}
